package com.idol.web.bean;

import com.idol.web.util.ResponseHeaderUtil;
import com.idol.web.util.StaticResourceUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * @author Supreme_Sir
 * @version 1.0
 * @className Response
 * @description 后台响应对象
 * @date 2020/11/20 21:02
 **/
public class Response {
    private OutputStream outputStream;

    public void outPutHtml(String filePath) throws IOException {
        if (null != this.outputStream) {
            File targetFile = new File(filePath);
            if (targetFile.exists() && targetFile.isFile()) {
                StaticResourceUtil.outPutStaticResource(new FileInputStream(targetFile), outputStream);
            } else {
                StaticResourceUtil.write(outputStream, ResponseHeaderUtil.getHttpHeader404());
            }
        }
    }


    public Response() {
    }

    public Response(OutputStream outputStream) {
        this.outputStream = outputStream;
    }

    public OutputStream getOutputStream() {
        return outputStream;
    }

    public void setOutputStream(OutputStream outputStream) {
        this.outputStream = outputStream;
    }
}
